-- @owner: @zou_jialiang050
-- @date: 2022/02/24
-- @testpoint: 在视图上构建truncate触发器，合理报错

--step1:建表;expect:成功
drop table if exists t_trigger_src_00062 cascade;
create table t_trigger_src_00062(id1 int, id2 int, id3 int) with (storage_type=ustore);

--step2:在视图上构建truncate触发器;expect:合理报错
create or replace view t_trigger_src_00062_view1 as select * from t_trigger_src_00062;
create or replace function insert_func()
returns trigger as $$
begin
truncate table t_trigger_src_00062;
return new;
end;
$$language plpgsql;
/
drop trigger if exists insert_trigger_1 on t_trigger_src_00062_view1;
create trigger insert_trigger_1
instead of truncate on t_trigger_src_00062_view1
for each row
execute procedure insert_func();
/
drop table if exists t_trigger_src_00062 cascade;
drop table if exists test_trigger_des_tbl cascade;
drop sequence if exists test_trigger_des_seq1 cascade;
create table t_trigger_src_00062(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table test_trigger_des_tbl(id1 int, id2 int, id3 int) with (storage_type=ustore);
create sequence test_trigger_des_seq1;
create or replace function insert_func()
returns trigger as $$
begin
truncate table t_trigger_src_00062;
return new;
end;
$$language plpgsql;
/
drop trigger if exists insert_trigger_1 on t_trigger_src_00062;
create trigger insert_trigger_1
instead of truncate on t_trigger_src_00062
for each row
execute procedure insert_func();
/

--step3:清理环境;expect:成功
drop trigger if exists insert_trigger_1 on t_trigger_src_00062;
drop table if exists t_trigger_src_00062 cascade;
drop view if exists t_trigger_src_00062_view1;
drop sequence if exists test_trigger_des_seq1 cascade;